//
//  CanYouDoItAppDelegate.cpp
//  CanYouDoIt
//
//  Created by hoangtx on 7/6/13.
//  Copyright __MyCompanyName__ 2013. All rights reserved.
//

#include "AppDelegate.h"

#include "cocos2d.h"
#include "SimpleAudioEngine.h"
#include "HelloWorldScene.h"
#include "StaticTapScene.h"
#include "SceneManager.h"
#include "ResultScene.h"
#include "QuickFingerMenuScene.h"
#include "HideAndSeekTapScene.h"
#include "QuickCircleTapScene.h"
#include "AvoidTheCircleGameScene.h"
#include "FollowTheCircleGameScene.h"
#include "ChooseTheRightColorGameScene.h"
#include "OrderTapGameScene.h"
#include "ControllerSlashGameScene.h"
#include "ThrowingBallGameScene.h"
USING_NS_CC;
using namespace CocosDenshion;

AppDelegate::AppDelegate()
{

}

AppDelegate::~AppDelegate()
{
}

bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    CCDirector *pDirector = CCDirector::sharedDirector();
    pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());

    // turn on display FPS
    pDirector->setDisplayStats(false);

    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 / 60);

    // create a scene. it's an autorelease object
    CCScene *staticTapScene = StaticTapScene::scene(10);
    staticTapScene->retain();
    SceneManager::sharedInstance()->staticTapScene = staticTapScene;
    CCScene* resultScene = ResultScene::scene();
    resultScene->retain();
    SceneManager::sharedInstance()->resultScene = resultScene;
    
    CCScene* quickFingerMenuScene = QuickFingerMenuScene::scene();
    quickFingerMenuScene->retain();
    SceneManager::sharedInstance()->quickFingerMenuScene = quickFingerMenuScene;
    
    CCScene* hideAndSeekScene = HideAndSeekTapScene::scene(10);
    hideAndSeekScene->retain();
    SceneManager::sharedInstance()->hideAndSeekScene = hideAndSeekScene;
    
    CCScene* quickCircleTapScene = QuickCircleTapScene::scene(10);
    quickCircleTapScene->retain();
    SceneManager::sharedInstance()->quickCircleTapScene = quickCircleTapScene;
    
    CCScene* avoidTheCircleGameScene = AvoidTheCircleGameScene::scene();
    avoidTheCircleGameScene->retain();
    SceneManager::sharedInstance()->avoidTheCircleGameScene = avoidTheCircleGameScene;
    
    CCScene* followTheCircleGameScene = FollowTheCircleGameScene::scene();
    followTheCircleGameScene->retain();
    SceneManager::sharedInstance()->followTheCircleGameScene = followTheCircleGameScene;
    
    CCScene* chooseTheRightColorGameScene = ChooseTheRightColorGameScene::scene(10);
    chooseTheRightColorGameScene->retain();
    SceneManager::sharedInstance()->chooseTheRightColorGameScene = chooseTheRightColorGameScene;
    
    CCScene* orderTapGameScene = OrderTapGameScene::scene(10);
    orderTapGameScene->retain();
    SceneManager::sharedInstance()->orderTapGameScene = orderTapGameScene;
    
    CCScene* controllerSplashGameScene = ControllerSlashGameScene::scene(20);
    controllerSplashGameScene->retain();
    SceneManager::sharedInstance()->controllerSplashGameScene = controllerSplashGameScene;
    
    CCScene* throwingBallGameScene = ThrowingBallGameScene::scene(20);
    throwingBallGameScene->retain();
    SceneManager::sharedInstance()->throwingBallGameScene = throwingBallGameScene;
    // run
    pDirector->runWithScene(quickFingerMenuScene);

    return true;
}

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground()
{
    CCDirector::sharedDirector()->stopAnimation();
    SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
    SimpleAudioEngine::sharedEngine()->pauseAllEffects();
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
    CCDirector::sharedDirector()->startAnimation();
    SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
    SimpleAudioEngine::sharedEngine()->resumeAllEffects();
}
